<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
 public static $user = '';
 public static $invite_users = '';
	public function _initialize()
	{	
    
		$user=session('user');
    if (empty($user)){
       $this->error('请先登录',U('Login/login')); 
    }else{
      //var_dump($user);exit();
      if ($user['status']==0 || $user['status']==null ) {
       $this->error('请完善信息',U('login/info',array('id'=>$user['id'])));
      }

      $notice=M('notice')->order('add_time')->find();
    	$id=session("user.id");
       $invite_users=M('user')->where(array('invite_id'=>$id))->select(); //获取直属团队
       $jb=M('jbset')->find();
       foreach ($invite_users as $key => $value) {
         $invite_users[$key]['status']= $jb['jb'.$value['status']];
       }
       //var_dump($invite_users);exit();
      $jb=M('jbset')->find();
         	self::$user =M('user')->where(array('id'=>$id))->find();
           $registertime=self::$user['ctime']; 
 
      $month1 = strtotime("+1months",$registertime); 
      $month2  = strtotime("+2months",$registertime); 
      $month3  = strtotime("+3months",$registertime);
  if (self::$user['status']>1) {
 
          $map['invite_id']=$id;
          $map['status']=1;
          $invite_ids=M('user')->where($map)->field('id')->select();

          $order_m = new \Admin\Model\OrderModel();
          $month1_num=$order_m->getTeamTotalNums($id,$registertime,$month1);
          $month2_num=$order_m->getTeamTotalNums($id,$month1,$month2);
          $month3_num=$order_m->getTeamTotalNums($id,$month2,$month3);
          $total_num=$order_m->getTeamTotalNumsNow($id);
          //var_dump($total_num);exit();
          if ( count($invite_ids)>= $jb['sj_jb2_jb1s'] && $month1_num>=$jb['sj_jb2_orders'] && $month2_num>=$jb['sj_jb2_orders'] && $month3_num>=$jb['sj_jb2_orders']) {
           M('user')->where(array('id'=>$id))->setField('status',2);
          }
          
        $this->assign('month1_num',$month1_num);
        $this->assign('month2_num',$month2_num);
        $this->assign('month3_num',$month3_num);
        $this->assign('total_num',$total_num);
    }elseif (self::$user['status']==2) {
      //echo '业务员向上升级的条件';
    }elseif (self::$user['status']==3) {
     // echo '连锁店向上升级的条件';
    }else{
     // echo "分公司";
    }
      //var_dump(self::$user);exit();
          $this->assign('user',self::$user);
          $this->assign('notice',$notice);
          self::$invite_users=$invite_users;
         	$this->assign('invite_users',$invite_users);
  }

		 

	}


	
}
